package com.dfqy.service;

import com.dfqy.dao.AppointDao;
import com.dfqy.pojo.Appoint;
import com.dfqy.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Author : atyushu
 * Package : com.dfqy.service
 * ClassName : AppointService
 * Create : 2023/8/1 - 13:10
 * Version : v1.0
 * Description : The class of service for Appoint.
 */
@Service
@Cacheable(keyGenerator = "keyg", cacheNames = "appoint")
@Transactional(rollbackFor = Exception.class, propagation = Propagation.SUPPORTS)
public class AppointService {

    @Autowired
    private AppointDao appointDao;

    @CacheEvict(allEntries = true, cacheNames = "appoint")
    public int insert(Appoint appoint) {
        return appointDao.insert(appoint);
    }

    @CacheEvict(allEntries = true, cacheNames = "appoint")
    public int delete(long... id) {
        return appointDao.delete(id);
    }

    @CacheEvict(allEntries = true, cacheNames = "appoint")
    public int update(Appoint appoint) {
        return appointDao.update(appoint);
    }

    public Appoint getById(long id) {
        return appointDao.getById(id);
    }

    public Page<Appoint> page(int page, int limit, String phone, String addrbranch, String courseof, Date posttimeStart, Date posttimeEnd, String uname) {
        return new Page<>(appointDao.page(page, limit, phone, addrbranch, courseof, posttimeStart, posttimeEnd, uname), page, appointDao.countByLike(phone, addrbranch, courseof, posttimeStart, posttimeEnd, uname), limit);
    }
}
